package com.qfedu.mesadmin.dev.type.controller;

import com.qfedu.mes.common.CommonResult;
import com.qfedu.mes.entity.dev.DeviceType;
import com.qfedu.mesadmin.dev.type.params.AddTypeParam;
import com.qfedu.mesadmin.dev.type.params.SearchParam;
import com.qfedu.mesadmin.dev.type.service.DeviceService;
import com.qfedu.mesadmin.dev.type.vo.DeviceTypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dev/man")
public class DeviceController {
    @Resource
    private DeviceService deviceService;
   @PostMapping("/add")
    public CommonResult addDevice(@RequestBody AddTypeParam param){
        deviceService.addDevice(param);
        return CommonResult.success();
    }

    @GetMapping("/list")
    public CommonResult devTypeList(){
        List<DeviceTypeVO> deviceTypeVOS = deviceService.selectDevTypeTree();
        return CommonResult.success(deviceTypeVOS);
    }

    @PostMapping("/select/list")
    public CommonResult selectLike(@RequestBody SearchParam param){
        List<DeviceType> deviceTypes = deviceService.selectLike(param);
        return CommonResult.success(deviceTypes);
    }
    @GetMapping("/info")
    public CommonResult devInfo(Integer id){
        DeviceType deviceType = deviceService.devInfo(id);
        return CommonResult.success(deviceType);
    }

    @PostMapping("/update")
    public CommonResult updateDev(@RequestBody DeviceType deviceType){
       deviceService.updateDev(deviceType);
       return CommonResult.success();
    }

}
